/**
 * @param { import("knex").Knex } knex
 * @returns { Promise<void> }
 */
exports.up = function(knex) {
  return knex.schema.createTable('users', function(table) {
    table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
    table.string('username', 50).unique().notNullable();
    table.string('email', 100).unique().notNullable();
    table.string('password_hash').notNullable();
    table.string('first_name', 50);
    table.string('last_name', 50);
    table.string('phone', 20);
    table.enum('status', ['active', 'inactive', 'suspended']).defaultTo('active');
    table.enum('role', ['admin', 'user', 'moderator']).defaultTo('user');
    table.timestamp('email_verified_at').nullable();
    table.timestamp('last_login_at').nullable();
    table.timestamps(true, true); // created_at, updated_at
    table.timestamp('deleted_at').nullable(); // soft delete
    
    // Indexes
    table.index(['email']);
    table.index(['username']);
    table.index(['status']);
    table.index(['created_at']);
  });
};

/**
 * @param { import("knex").Knex } knex
 * @returns { Promise<void> }
 */
exports.down = function(knex) {
  return knex.schema.dropTable('users');
};